package com.zq.car.controller;


import com.zq.car.dao.dto.CartSaveDto;
import com.zq.car.dao.dto.CartUpdateCheck;
import com.zq.car.dao.entity.CartInfo;
import com.zq.car.service.ICartInfoService;
import com.zq.common.util.Result;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 购物车信息表 前端控制器
 * </p>
 *
 * @author 张乔
 * @since 2025-06-01
 */
@RestController
@RequestMapping("/car/cart-info")
public class CartInfoController {

@Resource
    private ICartInfoService cartInfoService;



@PostMapping("/save")
public Result<String> save(@RequestHeader("userToken") String token,
                           @RequestBody CartSaveDto cartSaveDto){
cartInfoService.saveCartInfo(cartSaveDto,token);
    return Result.success();
}
    @GetMapping("/getList")
    public Result<List<CartInfo>> list(@RequestHeader("userToken") String token){
  List<CartInfo> cartInfoList= cartInfoService.getList(token);
        return Result.successData(cartInfoList);
    }

//删除购物车
    @DeleteMapping("/deleteById/{id}")
public Result<String> deleteById(@RequestHeader("userToken") String token,
                           @PathVariable Integer id) {
        cartInfoService.deleteById(token,id);
        return Result.success();
    }

//修改购物车的选中状态
@PutMapping("/updateSelect")
    public Result<String> updateSelect(@RequestHeader("userToken") String token,
                           @RequestBody CartUpdateCheck cartUpdateCheck) {
        cartInfoService.updateSelect(token,cartUpdateCheck);
        return Result.success();
    }
//    获取当前登录用户选中的购物项列表数据

    @GetMapping("/auth/getAllChecked")
    public Result<Object> getAllChecked(@RequestHeader("userToken") String token) {
        List<CartInfo> cartInfoList = cartInfoService.getAllCkecked(token) ;
        return Result.successData(cartInfoList);
    }
//根据id查询购物车
    @GetMapping("/getByOrderId/{orderId}")
    public Result<Object> getByOrderId(@PathVariable Long orderId) {
    CartInfo cartInfoList = cartInfoService.getByOrderId(orderId);
        return Result.successData(cartInfoList);
    }

//    获取当前登录用户选中的购物项列表数据并已经勾选了
    @GetMapping("/auth/getAllCheckedAndCheck")
    public Result<Object> getAllCkeckedcart(@RequestHeader("userToken") String token) {
        List<CartInfo> cartInfoList = cartInfoService.getAllCkeckedcart(token) ;
        return Result.successData(cartInfoList);
    }

//删除用户已经选中的购物车
    @GetMapping("/deleteChecked")
    public Result<Object> deleteChecked(@RequestHeader("userToken") String token) {
        cartInfoService.deleteChecked(token);
        return Result.success();
    }


}
